package com.hospitalsystem.controller;

import com.hospitalsystem.entity.Arrange;
import com.hospitalsystem.service.ArrangeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Arrange)表控制层
 *
 * @author makejava
 * @since 2024-12-28 19:24:16
 */
@RestController
@RequestMapping("arrange")
public class ArrangeController {
    /**
     * 服务对象
     */
    @Resource
    private ArrangeService arrangeService;

    /**
     * 分页查询
     *
     * @param arrange 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Arrange>> queryByPage(Arrange arrange, PageRequest pageRequest) {
        return ResponseEntity.ok(this.arrangeService.queryByPage(arrange, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param arrangeId
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Arrange> queryById(@PathVariable("id")String arrangeId) {
        return ResponseEntity.ok(this.arrangeService.queryById(arrangeId));
    }

    /**
     * 新增数据
     *
     * @param arrange 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Arrange> add(Arrange arrange) {
        return ResponseEntity.ok(this.arrangeService.insert(arrange));
    }

    /**
     * 编辑数据
     *
     * @param arrange 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Arrange> edit(Arrange arrange) {
        return ResponseEntity.ok(this.arrangeService.update(arrange));
    }

    /**
     * 删除数据
     *
     * @param arrangeId
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String arrangeId) {
        return ResponseEntity.ok(this.arrangeService.deleteById(arrangeId));
    }

}

